package com.amethyst.web.controller;

import com.amethyst.model.Student;
import com.amethyst.model.TestModel;
import com.amethyst.service.service.StudentService;
import com.amethyst.service.mapper.StudentMapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Amethyst
 * @date 2023/3/15 13:48
 */
@RestController
@RequiredArgsConstructor
public class StudentController {

    private final StudentService studentService;

    private final StudentMapper studentMapper;

    @GetMapping("/student")
    public String getStudentModel() {
        Student student = new Student();
        student.setName("zhangsan");
        return student.toString();
    }

    @GetMapping("/student/service")
    public List<Student> getStudentService() {
        return studentService.list();
    }

    @GetMapping("/student/service/mapper")
    public List<Student> getStudentServiceMapper() {
        return studentService.getStudentServiceMapper();
    }

    @GetMapping("/student/service/mapper/xml")
    public Student getStudentServiceMapperXml(String name) {
        return studentService.getStudentServiceMapperXml(name);
    }

    @GetMapping("/student/mapper")
    public List<Student> getStudentMapper() {
        return studentMapper.selectList(Wrappers.emptyWrapper());
    }

    @GetMapping("/student/mapper/xml")
    public Student getStudentMapperXml(String name) {
        return studentMapper.getStudent(name);
    }

    public static void main(String[] args) {
        Student s = new Student();
        s.setName("zhang");
        System.out.println("-----" + s.getName());
        System.out.println("------" + TestModel.TEST);
    }
}
